Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[Pytanie]Powtarzająca się funkcja


Rekomendowane odpowiedzi

Opublikowano

Witam, mam pytanie, a właściwie problem.

Ludzie często z przyzwyczajenia klikają na coś kilka razy.

Jeżeli już ktoś kliknie na mój button np.10 razy to funkcja zostaje też wykonana 10 razy :/.

To przeskadza. Jak zrobić żeby po ponownym kliknięciu na button wykonywanie funkcji zostało przerwane i funkcja została wykonana ponownie tylko raz?

obraz24.png


Opublikowano

dodaj zmienną którą będziesz tooglował (między wartościami 1-0 za pomocą operatora not) podczas przyciśnięcia buttona. Jeśli będzie wynosić 1 (lub 0, to od Ciebie zależy) to wykona się funkcja.

Opublikowano

Global $pause = True
GUICreate("")
$toggle_button = GUICtrlCreateButton("", 10, 10, 10, 10)
GUISetState()

While 1
Switch GUIGetMsg()
Case -3
Exit
Case $toggle_button
toogle()
EndSwitch
If Not $pause Then
Send("a")
EndIf
Sleep(1)
WEnd

Func toogle()
$pause = Not $pause
EndFunc   ;==>toogle

Opublikowano

Dobrze znalazłem lepsze rozwiązanie.

$GUI_DISABLE

 

Teraz mam problem mam button do którego mam przypisaną taką funkcję:

Func Exxit()
Exit
EndFunc

I wszystko działa, po kliknięciu program się zamyka. Tylko kiedy włączę funkcję Start() to funkcja Exxit() już nie działa :(.

Jak to rozwiązać?

obraz24.png


Opublikowano

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <file.au3>
#include <array.au3>
#include <String.au3>
#Include <Constants.au3>
#Include <GuiEdit.au3>

$Form1 = GUICreate("xxxxxxxxxxxxxxxxx", 401, 451, 192, 124)
$CreateIE = _IECreateEmbedded()
$OknoIE = GUICtrlCreateObj($CreateIE, 16, 144, 369, 289)
$Start = GUICtrlCreateButton("Start", 16, 88, 121, 41, $WS_GROUP)
$Stop = GUICtrlCreateButton("Stop", 168, 88, 121, 41, $WS_GROUP)
$About = GUICtrlCreateButton("About", 312, 47, 73, 25, $WS_GROUP)
$Exit = GUICtrlCreateButton("Exit", 312, 95, 73, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("http://", 64, 16, 321, 21)
$Input2 = GUICtrlCreateInput("300", 80, 48, 57, 21)
$Input3 = GUICtrlCreateInput("2", 232, 48, 57, 21)
$Label1 = GUICtrlCreateLabel("Address:", 16, 19, 45, 17)
$Label2 = GUICtrlCreateLabel("Repetitions:", 16, 51, 60, 17)
$Label3 = GUICtrlCreateLabel("Intervals [s]:", 168, 51, 61, 17)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Case $Start
Start()
Case $Stop
Stop()
Case $Exit
Exxit()
EndSwitch
WEnd


Func Start()
GUICtrlSetState($Start, $GUI_DISABLE)
GUICtrlSetState($Input1, $GUI_DISABLE)
GUICtrlSetState($Input2, $GUI_DISABLE)
GUICtrlSetState($Input3, $GUI_DISABLE)
$Adres = GUICtrlRead($Input1)
$Ilosc = GUICtrlRead($Input2)
$Czas = GUICtrlRead($Input3)
Do
	_IENavigate($CreateIE, $Adres)

	$Ilosc=$Ilosc-1
	GUICtrlSetData($Input2, $Ilosc)

	Sleep($Czas*1000)
Until $Ilosc=0
EndFunc


Func Stop()
;Co tutaj wpisać żeby wyskoczyć z pętli w funkcji Start()?
GUICtrlSetState($Start, $GUI_ENABLE)
GUICtrlSetState($Input1, $GUI_ENABLE)
GUICtrlSetState($Input2, $GUI_ENABLE)
GUICtrlSetState($Input3, $GUI_ENABLE)
EndFunc

Func Exxit()
Exit
EndFunc

 

Próbowałem na początku programu dać zmienną $On = 1

A w funkcji Start(), w pętli:

If $On = 2 Then
ExitLoop
EndIf

Natomiast w funkcji Stop():

GUICtrlSetData($On, 2)

Ale wtedy po kliknięciu na button Start odrazu program się wyłączał.

obraz24.png


Opublikowano

jest tak dlatego, bo po przejściu do funkcji start() program nie rejestruje zdarzeń z gui. Albo to dodaj w funkcji start(), albo ogarnij to w głównej pętli

Opublikowano

Func Start()
GUICtrlSetState($Start, $GUI_DISABLE)
GUICtrlSetState($Input1, $GUI_DISABLE)
GUICtrlSetState($Input2, $GUI_DISABLE)
GUICtrlSetState($Input3, $GUI_DISABLE)
$Adres = GUICtrlRead($Input1)
$Ilosc = GUICtrlRead($Input2)
$Czas = GUICtrlRead($Input3)
       Do
$nMsg = GUIGetMsg()
Switch $nMsg
       Case $GUI_EVENT_CLOSE
Case $Start
Start()
Case $Stop
       Stop()
Case $Exit
       Exxit()
EndSwitch

               _IENavigate($CreateIE, $Adres)

               $Ilosc=$Ilosc-1
               GUICtrlSetData($Input2, $Ilosc)

               Sleep($Czas*1000)
       Until $Ilosc=0 

EndFunc

tak najprościej.

Opublikowano

Sprawdzałeś to u siebie? U mnie nie chce działać, dalej jest to samo.

@Edit Jak usunąłem Sleep to wszystko działa tylko sleep jest mi potrzebny da się go jakoś zastąpić?

obraz24.png


Opublikowano

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <file.au3>
#include <array.au3>
#include <String.au3>
#include <Constants.au3>
#include <GuiEdit.au3>
$play = False ; ta zmienna bedzie oznaczać czy ma byc wykonywana funckja start
$Form1 = GUICreate("xxxxxxxxxxxxxxxxx", 401, 451, 192, 124)
$CreateIE = _IECreateEmbedded()
$OknoIE = GUICtrlCreateObj($CreateIE, 16, 144, 369, 289)
$Start = GUICtrlCreateButton("Start", 16, 88, 121, 41, $WS_GROUP)
$Stop = GUICtrlCreateButton("Stop", 168, 88, 121, 41, $WS_GROUP)
$About = GUICtrlCreateButton("About", 312, 47, 73, 25, $WS_GROUP)
$Exit = GUICtrlCreateButton("Exit", 312, 95, 73, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("http://", 64, 16, 321, 21)
$Input2 = GUICtrlCreateInput("300", 80, 48, 57, 21)
$Input3 = GUICtrlCreateInput("2", 232, 48, 57, 21)
$Label1 = GUICtrlCreateLabel("Address:", 16, 19, 45, 17)
$Label2 = GUICtrlCreateLabel("Repetitions:", 16, 51, 60, 17)
$Label3 = GUICtrlCreateLabel("Intervals [s]:", 168, 51, 61, 17)
GUISetState(@SW_SHOW)
$timer = TimerInit() ;inicjujemy timer
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
 Case $GUI_EVENT_CLOSE
 Case $Start
  GUICtrlSetState($Start, $GUI_DISABLE) ;wyrzuciłem to poza funkcje
  GUICtrlSetState($Input1, $GUI_DISABLE)
  GUICtrlSetState($Input2, $GUI_DISABLE)
  GUICtrlSetState($Input3, $GUI_DISABLE)
  $Adres = GUICtrlRead($Input1)
  $Ilosc = GUICtrlRead($Input2)
  $Czas = GUICtrlRead($Input3)
  $play = True
 Case $Stop
  stop()
 Case $Exit
  Exxit()
EndSwitch
If $play And TimerDiff($timer) > $Czas * 1000 And $Ilosc > 0 Then ; sprawdzaamy czy timer naliczyl więcej sekund niz w inpucie, czy ilosc doszla do konca i czy jest $play
 start()
 $timer = TimerInit()
EndIf
WEnd

Func start()
_IENavigate($CreateIE, $Adres)
$Ilosc = $Ilosc - 1
GUICtrlSetData($Input2, $Ilosc)
EndFunc   ;==>Start

Func stop()
;Co tutaj wpisać żeby wyskoczyć z pętli w funkcji Start()?
GUICtrlSetState($Start, $GUI_ENABLE)
GUICtrlSetState($Input1, $GUI_ENABLE)
GUICtrlSetState($Input2, $GUI_ENABLE)
GUICtrlSetState($Input3, $GUI_ENABLE)
$play = False
EndFunc   ;==>Stop
Func Exxit()
Exit
EndFunc   ;==>Exxit

proszę, cały kod

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...